cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //    default: null,      // The default value will be used only when the component attaching
        //                           to a node for the first time
        //    url: cc.Texture2D,  // optional, default is typeof default
        //    serializable: true, // optional, default is true
        //    visible: true,      // optional, default is true
        //    displayName: 'Foo', // optional
        //    readonly: false,    // optional, default is false
        // },
        // ...
        _menu:null,
    },

    // use this for initialization
    onLoad: function () {
        var btnMenu = cc.find("Canvas/btn_menu");
        cc.addClickEvent(btnMenu,this.node,"Menu","onBtnClicked");
        
        this._menu = cc.find("Canvas/menu");
        this._menu.active = false;
        cc.addClickEvent(this._menu,this.node,"Menu","onBtnClicked");
        
        cc.addClickEvent(cc.find("Canvas/menu/btns/btn_menu_wjck"),this.node,"Menu","onBtnMenuClicked");
        cc.addClickEvent(cc.find("Canvas/menu/btns/btn_menu_hdgg"),this.node,"Menu","onBtnMenuClicked");
        cc.addClickEvent(cc.find("Canvas/menu/btns/btn_menu_wddd"),this.node,"Menu","onBtnMenuClicked");
        cc.addClickEvent(cc.find("Canvas/menu/btns/btn_menu_gktj"),this.node,"Menu","onBtnMenuClicked");
        cc.addClickEvent(cc.find("Canvas/menu/btns/btn_menu_wdxx"),this.node,"Menu","onBtnMenuClicked");
        cc.addClickEvent(cc.find("Canvas/menu/btns/btn_menu_exit"),this.node,"Menu","onBtnMenuClicked");
        
        
        this.node.on("switch_page",function(data){
           var pageName = data.detail;
           btnMenu.active = pageName != "login";
        }.bind(this));
    },
    
    onBtnClicked:function(event){
        if(event.target.name == "btn_menu"){
            this._menu.active = true;    
        }
        else if(event.target.name == "menu"){
            this._menu.active = false;
        }
    },
    
    onBtnMenuClicked:function(event){
        if(event.target.name == "btn_menu_wjck"){
            this.node.emit("switch_page","wjck");
        }
        else if(event.target.name == "btn_menu_hdgg"){
            this.node.emit("switch_page","hdgg");
        }
        else if(event.target.name == "btn_menu_wddd"){
            this.node.emit("switch_page","wddd");
        }
        else if(event.target.name == "btn_menu_gktj"){
            this.node.emit("switch_page","gktj");
        }
        else if(event.target.name == "btn_menu_wdxx"){
            this.node.emit("switch_page","wdxx");
        }
        else if(event.target.name == "btn_menu_exit"){
            cc.alert.show("提示","您确定要退出登录状态么？",function(){
                this.node.emit("switch_page","login");    
            },true);
            
        }
        this._menu.active = false;
    }

    // called every frame, uncomment this function to activate update callback
    // update: function (dt) {

    // },
});
